package com.glory.hzlionpda.activity;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.hzlionpda.R;
import com.glory.hzlionpda.adapter.InputDataListAdapter;
import com.glory.hzlionpda.adapter.SpcDataListAdapter;
import com.glory.hzlionpda.adapter.TrackOutCarryListAdapter;
import com.glory.hzlionpda.base.BasePollingActivity;
import com.glory.hzlionpda.base.Constant;
import com.glory.hzlionpda.bean.BaseBean;
import com.glory.hzlionpda.bean.ByLotJobBean;
import com.glory.hzlionpda.bean.CarryBean;
import com.glory.hzlionpda.bean.DefectCodeBean;
import com.glory.hzlionpda.bean.HoldBean;
import com.glory.hzlionpda.bean.InputDataBean;
import com.glory.hzlionpda.bean.LotBean;
import com.glory.hzlionpda.bean.SpcBean;
import com.glory.hzlionpda.utils.NetUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StringUtils;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class EndLotActivity extends BasePollingActivity {


    @BindView(R.id.tvLogId)
    TextView tvLogId;
    @BindView(R.id.tvEqpId)
    TextView tvEqpId;
    @BindView(R.id.tvStartTime)
    TextView tvStartTime;
    @BindView(R.id.tvEndTime)
    TextView tvEndTime;
    @BindView(R.id.tvTouNum)
    TextView tvTouNum;
    @BindView(R.id.tvPlanNum)
    TextView tvPlanNum;
    @BindView(R.id.tvTrueNum)
    TextView tvTrueNum;
    @BindView(R.id.tvInputTitle)
    TextView tvInputTitle;
    @BindView(R.id.tvChoose)
    TextView tvChoose;
    @BindView(R.id.ivDownArrow2)
    ImageView ivDownArrow2;
    @BindView(R.id.tvSubmitInput)
    TextView tvSubmitInput;
    @BindView(R.id.rlInput)
    RelativeLayout rlInput;
    @BindView(R.id.rvInputList)
    RecyclerView rvInputList;
    @BindView(R.id.tvRemark)
    TextView tvRemark;
    @BindView(R.id.tvSubmitRemark)
    TextView tvSubmitRemark;
    @BindView(R.id.etRemark)
    FreeUI_ClearEditText etRemark;
    @BindView(R.id.llContent)
    LinearLayout llContent;
    @BindView(R.id.tvCancel)
    TextView tvCancel;
    @BindView(R.id.tvEnd)
    TextView tvEnd;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvRunCheckNote)
    TextView tvRunCheckNote;
    @BindView(R.id.tvUser)
    TextView tvUser;
    @BindView(R.id.rvCarryList)
    RecyclerView rvCarryList;
    @BindView(R.id.llCarry)
    LinearLayout llCarry;
    //    @BindView(R.id.etDryer)
//    FreeUI_ClearEditText etDryer;
//    @BindView(R.id.llDryer)
//    LinearLayout llDryer;
    @BindView(R.id.llSpc)
    LinearLayout llSpc;
    @BindView(R.id.rvSpcList)
    RecyclerView rvSpcList;
    @BindView(R.id.tvNowStep)
    TextView tvNowStep;
    @BindView(R.id.tvNextStep)
    TextView tvNextStep;

    private String eqpId, lotId;
    private LotBean currentLotBean;
    private Animation animation, animationDismiss;
    private InputDataListAdapter inputDataListAdapter;
    private TrackOutCarryListAdapter trackOutCarryListAdapter;
    private SpcDataListAdapter spcDataListAdapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_end_lot;
    }

    @Override
    protected void initView() {
        tvUser.setText(Constant.CURRENT_USER);
        freeUI_titleView.setTitle("批次结束");
        rvInputList.setLayoutManager(new LinearLayoutManager(EndLotActivity.this));
        rvInputList.setItemAnimator(new DefaultItemAnimator());
        rvInputList.addItemDecoration(new DividerItemDecoration(EndLotActivity.this, 1));

        rvCarryList.setLayoutManager(new LinearLayoutManager(EndLotActivity.this));
        rvCarryList.setItemAnimator(new DefaultItemAnimator());
        rvCarryList.addItemDecoration(new DividerItemDecoration(EndLotActivity.this, 1));

        rvSpcList.setLayoutManager(new LinearLayoutManager(EndLotActivity.this));
        rvSpcList.setItemAnimator(new DefaultItemAnimator());
        rvSpcList.addItemDecoration(new DividerItemDecoration(EndLotActivity.this, 1));

        trackOutCarryListAdapter = new TrackOutCarryListAdapter(null);
        trackOutCarryListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        trackOutCarryListAdapter.isFirstOnly(true);
        rvCarryList.setAdapter(trackOutCarryListAdapter);

        spcDataListAdapter = new SpcDataListAdapter(null);
        spcDataListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        spcDataListAdapter.isFirstOnly(true);
        rvSpcList.setAdapter(spcDataListAdapter);
    }

    @Override
    protected void initData() {
        eqpId = getIntent().getStringExtra("eqpId");
        lotId = getIntent().getStringExtra("lotId");
        requestLotInfo();
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return new FreeUI_AddViewEntity(getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY), llMain);
    }

    private void requestLotInfo() {
//        String json = "{\"LOTID\":\"L21140038\",\"CHANGERECIPE\":\"\",\"ISLOTS\":\"N\",\"MATERIALIST\":[{\"MATERIANAME\":\"01\",\"MATERIAVALUE\":\"WF000001\"},{\"MATERIANAME\":\"02\",\"MATERIAVALUE\":\"WF000002\"}],\"STEPNAME\":\"E-CAEI\",\"MASKID\":\"\",\"WAFERLIST\":[{\"LOTID\":\"L21140038\",\"WAFER\":[{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_1\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_2\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_3\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_4\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_5\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_6\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_7\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_8\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_9\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_10\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_11\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_12\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_13\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_14\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_15\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_16\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_17\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_18\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_19\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_20\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_21\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_22\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_23\"},{\"SLOTNO\":\"18\",\"WAFERID\":\"L21140038_24\"}],\"WAFERQTYNO\":\"24\"}],\"NOWSTEPDESC\":\"接触区腐蚀后检查\",\"RECIPE\":\"\",\"STEPDTE\":\"88mil\",\"PROBEDEVICESTATUS\":\"Y\",\"EQPRECIPE\":\"\",\"PARTNAME\":\"S2151AE(001)\",\"RESULTMESSAGE\":\"Success\",\"JOBLOTLIST\":[\"L21140038\"],\"SPCLIST\":[],\"EQPSTATUS\":\"RUN\",\"PARAMETERGROUPBYLOT\":[{\"PARAMETERVALUE\":\"\",\"LOTID\":\"L21140038\",\"PARAMETERDESC\":\"检查片号\",\"LBLID\":\"检查片号\",\"SEQUENCENUMBER\":5,\"VALUELIST\":[],\"PARAMETERID\":\"LI_CHECK_ON\",\"COLLECTIONTYPE\":\"BY_LOT\",\"PARAMETERSEQ\":1}],\"RESULTCODE\":\"TRUE\",\"PARTVERSION\":\"\",\"DEFECTCODELIST\":[{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL001\",\"DATA_1_VALUE\":\"碎片\",\"TYPE\":\"defect\"},{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL008\",\"DATA_1_VALUE\":\"腐蚀残留\",\"TYPE\":\"defect\"},{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL009\",\"DATA_1_VALUE\":\"过腐蚀\",\"TYPE\":\"defect\"},{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL010\",\"DATA_1_VALUE\":\"划伤\",\"TYPE\":\"defect\"},{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL015\",\"DATA_1_VALUE\":\"颗粒\",\"TYPE\":\"defect\"},{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL018\",\"DATA_1_VALUE\":\"其他\",\"TYPE\":\"defect\"},{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL020\",\"DATA_1_VALUE\":\"缺口或裂纹\",\"TYPE\":\"defect\"},{\"TYPENAME\":\"缺陷\",\"REASONCODE\":\"DEFECT_ALL029\",\"DATA_1_VALUE\":\"沾污\",\"TYPE\":\"defect\"}],\"CUSTOMER\":\"ADMIN admin\",\"RUNCHECKNOTE\":\"\",\"PARAMETERGROUPBYJOB\":[],\"PARNAME\":\"N\",\"NEXTSTEPDESC\":\"001产品接触区去胶清洗\",\"RELATIONLIST\":[],\"RUNCHECKLIST\":[],\"RECIPEDESC\":\"\",\"HOLDCODE\":[{\"CODENAME\":\"HOLD_ALL001\",\"CODEVALUE\":\"碎片\"},{\"CODENAME\":\"HOLD_ALL002\",\"CODEVALUE\":\"包装不当\"},{\"CODENAME\":\"HOLD_ALL003\",\"CODEVALUE\":\"表面颜色异常\"},{\"CODENAME\":\"HOLD_ALL004\",\"CODEVALUE\":\"成品率低\"},{\"CODENAME\":\"HOLD_ALL005\",\"CODEVALUE\":\"程序错误\"},{\"CODENAME\":\"HOLD_ALL006\",\"CODEVALUE\":\"电特性异常\"},{\"CODENAME\":\"HOLD_ALL007\",\"CODEVALUE\":\"对准和曝光缺陷\"},{\"CODENAME\":\"HOLD_ALL008\",\"CODEVALUE\":\"腐蚀残留\"},{\"CODENAME\":\"HOLD_ALL009\",\"CODEVALUE\":\"过腐蚀\"},{\"CODENAME\":\"HOLD_ALL010\",\"CODEVALUE\":\"划伤\"},{\"CODENAME\":\"HOLD_ALL011\",\"CODEVALUE\":\"激光标识错误\"},{\"CODENAME\":\"HOLD_ALL012\",\"CODEVALUE\":\"金属厚度异常\"},{\"CODENAME\":\"HOLD_ALL013\",\"CODEVALUE\":\"金属缺陷\"},{\"CODENAME\":\"HOLD_ALL014\",\"CODEVALUE\":\"晶片缺陷\"},{\"CODENAME\":\"HOLD_ALL015\",\"CODEVALUE\":\"颗粒\"},{\"CODENAME\":\"HOLD_ALL016\",\"CODEVALUE\":\"墨点脱落\"},{\"CODENAME\":\"HOLD_ALL017\",\"CODEVALUE\":\"墨点形状不合格\"},{\"CODENAME\":\"HOLD_ALL018\",\"CODEVALUE\":\"其他\"},{\"CODENAME\":\"HOLD_ALL019\",\"CODEVALUE\":\"切割异常\"},{\"CODENAME\":\"HOLD_ALL020\",\"CODEVALUE\":\"缺口或裂纹\"},{\"CODENAME\":\"HOLD_ALL021\",\"CODEVALUE\":\"蠕虫\"},{\"CODENAME\":\"HOLD_ALL022\",\"CODEVALUE\":\"酸侵蚀\"},{\"CODENAME\":\"HOLD_ALL023\",\"CODEVALUE\":\"投片错误\"},{\"CODENAME\":\"HOLD_ALL024\",\"CODEVALUE\":\"涂胶缺陷\"},{\"CODENAME\":\"HOLD_ALL025\",\"CODEVALUE\":\"显影缺陷\"},{\"CODENAME\":\"HOLD_ALL026\",\"CODEVALUE\":\"氧化层厚度异常\"},{\"CODENAME\":\"HOLD_ALL027\",\"CODEVALUE\":\"氧化层划伤\"},{\"CODENAME\":\"HOLD_ALL028\",\"CODEVALUE\":\"原材料异常\"},{\"CODENAME\":\"HOLD_ALL029\",\"CODEVALUE\":\"沾污\"},{\"CODENAME\":\"HOLD_ALL030\",\"CODEVALUE\":\"标签等信息错误\"}],\"CARRIERLIST\":[],\"ACTIVERMS\":\"\",\"ISSPCUPLOAD\":\"N\",\"DEVICESTATUS\":\"Y\"}";
//        currentLotBean = (new Gson()).fromJson(json, new TypeToken<LotBean>() {
//        }.getType());
//        setPageInfo();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("EQPID", eqpId);
            jsonObject.put("OPID", Constant.CURRENT_USER);
            jsonObject.put("LOTID", lotId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        NetUtils.requestGetNet("LOTOUTREQUEST", this, jsonObject, new FreeUI_DialogEntityCallBack<LotBean>(
                new TypeToken<LotBean>() {
                }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<LotBean> response) {
                if (response.body().isSuccess(getApplicationContext())) {
                    currentLotBean = response.body();
                    if (currentLotBean != null) {
                        setPageInfo();
                    }
                } else {
                    new Handler().postDelayed(EndLotActivity.this::finish, 2000);
                }
            }

            @Override
            public void onError(Response<LotBean> response) {
                super.onError(response);
                new Handler().postDelayed(EndLotActivity.this::finish, 2000);
                loadError(response.getException(), "LOTOUTREQUEST");
            }
        });
    }

    private void setPageInfo() {
        if (currentLotBean.getISLOTS().equalsIgnoreCase("Y")) {
            llCarry.setVisibility(View.VISIBLE);
            if (currentLotBean.getPARNAME().equalsIgnoreCase("Y")) {
                trackOutCarryListAdapter.setIsShowDry(true);
            } else {
                trackOutCarryListAdapter.setIsShowDry(false);
            }
            trackOutCarryListAdapter.setNewData(currentLotBean.getCARRIERLIST());
        } else {
            llCarry.setVisibility(View.GONE);
        }
        if (currentLotBean.getISSPCUPLOAD().equalsIgnoreCase("Y")) {
            llSpc.setVisibility(View.VISIBLE);
            spcDataListAdapter.setNewData(currentLotBean.getSPCLIST());
        } else {
            llSpc.setVisibility(View.GONE);
        }
        refreshInputAdapter(currentLotBean.getRUNCHECKLIST());
        tvLogId.setText(currentLotBean.getLOTID());
        tvEqpId.setText(currentLotBean.getEQPID());
        tvStartTime.setText(currentLotBean.getSTARTTIME());
        tvEndTime.setText(currentLotBean.getENDTIME());
        tvTouNum.setText(currentLotBean.getWAFERQTY());
        tvTrueNum.setText(currentLotBean.getWAFERQTY());
        tvRunCheckNote.setText(currentLotBean.getRUNCHECKNOTE());
        tvNowStep.setText(currentLotBean.getNOWSTEPDESC());
        tvNextStep.setText(currentLotBean.getNEXTSTEPDESC());
    }

    private void refreshInputAdapter(List<InputDataBean> runchecklist) {
        inputDataListAdapter = new InputDataListAdapter(runchecklist);
        inputDataListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        inputDataListAdapter.isFirstOnly(true);
        rvInputList.setAdapter(inputDataListAdapter);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1101) {
            if (resultCode == 2101) {
                currentLotBean = (LotBean) data.getSerializableExtra("lotBean");
                boolean isWriteDefect = false;
                for (DefectCodeBean codeBean : currentLotBean.getDEFECTCODELIST()) {
                    if (!FreeApi_StringUtils.isEmpty(codeBean.getUNITLIST()) ||
                            !FreeApi_StringUtils.isEmpty(codeBean.getLOTID()) ||
                            !FreeApi_StringUtils.isEmpty(codeBean.getREASONS())) {
                        isWriteDefect = true;
                        break;
                    }
                }
                tvEnd.setEnabled(!isWriteDefect);
                if (isWriteDefect) {
                    tvEnd.setBackgroundColor(getResources().getColor(R.color.free_ui_blue_sky_text_gray));
                } else {
                    tvEnd.setBackground(getResources().getDrawable(R.drawable.free_ui_blue_sky_selector_blue_click_no_corner_background));
                }
            } else if (resultCode == 2102) {
                String type = data.getStringExtra("type");
                String code = data.getStringExtra("code");
                String lots = data.getStringExtra("lots");
                requestTrackOut("Y", code, type, lots);
            }
        }
    }

    private void requestTrackOut(String isHold, String code, String type, String lots) {
        List<ByLotJobBean> byLotBeanList = currentLotBean.getPARAMETERGROUPBYLOT_TEMP();
        if (currentLotBean.getPARAMETERGROUPBYLOT().size()!=0&&byLotBeanList.size()==0){
            showToast("请填写BYLOT参数", false);
            return;
        }
        if (byLotBeanList.size() != 0) {
            boolean isOk = true;
            for (ByLotJobBean byLotBean : byLotBeanList) {
                if (byLotBean.getPARAMETERVALUE().isEmpty()) {
                    isOk = false;
                    break;
                }
            }
            if (!isOk) {
                showToast("请填写BYLOT参数", false);
                return;
            }
        }
        List<ByLotJobBean> byJobBeanList = currentLotBean.getPARAMETERGROUPBYJOB();
        if (byJobBeanList.size() != 0) {
            boolean isOk = true;
            for (ByLotJobBean byJobBean : byJobBeanList) {
                if (byJobBean.getPARAMETERVALUE().isEmpty()) {
                    isOk = false;
                    break;
                }
            }
            if (!isOk) {
                showToast("请填写BYJOB参数", false);
                return;
            }
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("EQPID", eqpId);
            jsonObject.put("OPID", Constant.CURRENT_USER);
            jsonObject.put("LOTID", lotId);
            jsonObject.put("ISHOLD", isHold);
            if (isHold.equals("Y")) {
                jsonObject.put("HOLDTYPE", type);
                jsonObject.put("HOLDCODE", code);
                jsonObject.put("LOTS", lots);
            }
            jsonObject.put("DRYID", "");
            jsonObject.put("WHEELS", "");
            jsonObject.put("BOAT", "");
            jsonObject.put("COMMENTS", "");
            jsonObject.put("RUNCHECKNOTE", tvRunCheckNote.getText().toString());
            jsonObject.put("RUNCHECKLIST", new JSONArray(new Gson().toJson(inputDataListAdapter.getData())));
            List<HoldBean> holdBeans = new ArrayList<>();
            jsonObject.put("HOLDLIST", new JSONArray(new Gson().toJson(holdBeans)));
            jsonObject.put("YCCLLIST", new JSONArray(new Gson().toJson(currentLotBean.getDEFECTCODELIST())));
            jsonObject.put("PARAMETERGROUPBYLOT", new JSONArray(new Gson().toJson(currentLotBean.getPARAMETERGROUPBYLOT_TEMP())));
            jsonObject.put("PARAMETERGROUPBYJOB", new JSONArray(new Gson().toJson(currentLotBean.getPARAMETERGROUPBYJOB())));
            if (llSpc.getVisibility() == View.VISIBLE) {
                jsonObject.put("SPCLIST", new JSONArray(new Gson().toJson(spcDataListAdapter.getData())));
            }
            if (llCarry.getVisibility() == View.VISIBLE) {
                jsonObject.put("CARRIERLIST", new JSONArray(new Gson().toJson(trackOutCarryListAdapter.getData())));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        NetUtils.requestGetNet("TRACKOUTREQUEST", this, jsonObject, new FreeUI_DialogEntityCallBack<BaseBean>(
                new TypeToken<BaseBean>() {
                }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<BaseBean> response) {
                if (response.body().isSuccess(getApplicationContext())) {
                    if (response.body().getRESULTMESSAGE().isEmpty()) {
                        showToast("出站成功", true);
                        EndLotActivity.this.finish();
                    } else {
                        FreeApi_DialogUtils.getConfirmDialog(getApplicationContext(), "确定", response.body().getRESULTMESSAGE(),
                                EndLotActivity.this::finish).show(getSupportFragmentManager(), "freeUI_generalFragmentDialog");
                    }
                }
            }

            @Override
            public void onError(Response<BaseBean> response) {
                super.onError(response);
                loadError(response.getException(), "TRACKOUTREQUEST");
            }
        });
    }

    @OnClick({R.id.llDefect, R.id.llByLot, R.id.llByJob, R.id.tvChoose, R.id.tvSubmitInput, R.id.tvSubmitRemark, R.id.rlInput, R.id.tvEnd, R.id.tvCancel})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.llDefect:
                Intent defectIntent = new Intent();
                defectIntent.putExtra("lotBean", currentLotBean);
                defectIntent.setClass(EndLotActivity.this, DefectInputActivity.class);
                startActivityForResult(defectIntent, 1101);
                break;
            case R.id.llByLot:
                Intent byLotIntent = new Intent();
                byLotIntent.putExtra("where", 1);
                byLotIntent.putExtra("lotBean", currentLotBean);
                byLotIntent.setClass(EndLotActivity.this, ByLotOrJobInputActivity.class);
                startActivityForResult(byLotIntent, 1101);
                break;
            case R.id.llByJob:
                Intent byJobIntent = new Intent();
                byJobIntent.putExtra("where", 2);
                byJobIntent.putExtra("lotBean", currentLotBean);
                byJobIntent.setClass(EndLotActivity.this, ByLotOrJobInputActivity.class);
                startActivityForResult(byJobIntent, 1101);
                break;
            case R.id.rlInput:
                if (rvInputList.getVisibility() == View.VISIBLE) {
                    if (animation == null) {
                        animation = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF,
                                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                        animation.setDuration(500);
                        animation.setFillAfter(true);
                    }
                    ivDownArrow2.startAnimation(animation);
                    rvInputList.setVisibility(View.GONE);
                } else {
                    if (animationDismiss == null) {
                        animationDismiss = new RotateAnimation(180f, 0f, Animation.RELATIVE_TO_SELF,
                                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                        animationDismiss.setDuration(500);
                        animationDismiss.setFillAfter(true);
                    }
                    ivDownArrow2.startAnimation(animationDismiss);
                    rvInputList.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.tvSubmitInput:
                break;
            case R.id.tvSubmitRemark:
                break;
            case R.id.tvEnd:
                if (isSetAll()) {
                    requestTrackOut("N", "", "", "");
                }
                break;
            case R.id.tvCancel:
                if (isSetAll()) {
                    Intent holdIntent = new Intent();
                    holdIntent.putExtra("currentLotBean", currentLotBean);
                    holdIntent.setClass(EndLotActivity.this, HoldActivity.class);
                    startActivityForResult(holdIntent, 1101);
                }
                break;
        }
    }

    private boolean isSetAll() {
        if (currentLotBean == null) {
            showToast("页面信息未获取成功，请退出重试", false);
            return false;
        }
        boolean isOk = true;
        for (InputDataBean inputDataBean : inputDataListAdapter.getData()) {
            if (inputDataBean.getXMMVALUE().length() == 0) {
                isOk = false;
                break;
            }
        }
        if (!isOk) {
            showToast("请完整填写运行记录", false);
            return false;
        }
        if (llCarry.getVisibility() == View.VISIBLE) {
            boolean isOk2 = true;
            for (CarryBean carryBean : trackOutCarryListAdapter.getData()) {
                if (!carryBean.isSelect()) {
                    isOk2 = false;
                    break;
                }
            }
            if (!isOk2) {
                showToast("请验证载具列表中的每一项LOT ID", false);
                return false;
            }
            if (currentLotBean.getPARNAME().equalsIgnoreCase("y")) {
                boolean isOk3 = true;
                for (CarryBean carryBean : trackOutCarryListAdapter.getData()) {
                    if (carryBean.getDRYID().isEmpty()) {
                        isOk3 = false;
                        break;
                    }
                }
                if (!isOk3) {
                    showToast("请填写载具列表中的每一项DryId", false);
                    return false;
                }
            }
        }
//        String dryerId = etDryer.getText().toString().trim();
//        if (llDryer.getVisibility() == View.VISIBLE && FreeApi_StringUtils.isEmpty(dryerId)) {
//            showToast("请扫描甩干机编号", false);
//            return false;
//        }

        if (llSpc.getVisibility() == View.VISIBLE) {
            boolean isSpcOk = true;
            for (SpcBean spcBean : spcDataListAdapter.getData()) {
                if (spcBean.getVALUE().length() == 0) {
                    isSpcOk = false;
                    break;
                }
            }
            if (!isSpcOk) {
                showToast("请完整填写SPC数据", false);
                return false;
            }
        }
        return true;
    }


//    private void requestAbort(String reason) {
//        if (currentLotBean == null) {
//            showToast("设备信息未获取成功，请退出重试", false);
//            return;
//        }
//        JSONObject jsonObject = new JSONObject();
//        try {
//            jsonObject.put("EQPID", eqpId);
//            jsonObject.put("OPID", Constant.CURRENT_USER);
//            jsonObject.put("LOTID", lotId);
//            List<HoldBean> holdBeans = new ArrayList<>();
//            holdBeans.add(new HoldBean(reason));
//            jsonObject.put("HOLDLIST", new JSONArray(new Gson().toJson(holdBeans)));
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        NetUtils.requestGetNet("ABORTREQUEST", this, jsonObject, new FreeUI_DialogEntityCallBack<BaseBean>(
//                new TypeToken<BaseBean>() {
//                }.getType(), getSupportFragmentManager(), this) {
//            @Override
//            public void onSuccess(Response<BaseBean> response) {
//                if (response.body().isSuccess(getApplicationContext())) {
//                    showToast("退站成功", true);
//                    EndLotActivity.this.finish();
//                }
//            }
//
//            @Override
//            public void onError(Response<BaseBean> response) {
//                super.onError(response);
//                loadError(response.getException(), "ABORTREQUEST");
//            }
//        });
//    }
}

